// 引用
import JSEncrypt from '@/static/js/jsencrypt.js'

// 公钥
const publicKey =
    'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDA7G/+JIjOfJJAf7Lx1jlvutzz\n'+
    'w0x4kWLSHhpNLOPDh9V/Uq2Ozzt8buw6bGPVc3ips6wEWkn04q7iaHeGM2OF6K4z\n'+
    'OXonrefhwkBanyk51R6IhIjjsxFu9Ah/yue1rQNrwxnQl1H5RsjnruYRGXNsNvzR\n'+
    'JhEGhwnSx/FhrGBFFwIDAQAB'
// 私钥
const privateKey =
    'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALUvpyUF2PxMw1Ma\n'

// 加密
export function rsaEncrypt(txt) {
    const encryptor = new JSEncrypt() // 创建加密对象实例
    encryptor.setPublicKey(publicKey) // 设置公钥
    return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function rsaDecrypt(txt) {
    const decryptor = new JSEncrypt() // 创建解密对象实例
    decryptor.setPrivateKey(privateKey) // 设置私钥
    return decryptor.decrypt(txt) // 对数据进行解密
}